﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace System
{
    public static class FileInfoExtension
    {
        private static string Md5(this FileInfo fi)
        {
            using (System.IO.FileStream oFileStream = fi.OpenRead())
            {
                MD5CryptoServiceProvider oMd5Hasher = new MD5CryptoServiceProvider();

                byte[] arrbytHashValue = oMd5Hasher.ComputeHash(oFileStream);//计算指定Stream 对象的哈希值

                //由以连字符分隔的十六进制对构成的String，其中每一对表示value 中对应的元素；例如“F-2C-4A”
                string hashData = BitConverter.ToString(arrbytHashValue);
                //替换-
                hashData = hashData.Replace("-", "");
           

                return hashData;
            }
        }
    }
}
